import uuid
import random
import time
import logging
from dataclasses import dataclass
import math
import sys
import pathlib
import os
from typing import List
import numpy
import inspect
from urllib.parse import quote_plus

logger = logging.getLogger(__name__)

CURRENTDIR = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
PARENTDIR = os.path.dirname(CURRENTDIR)
sys.path.insert(0, CURRENTDIR)
sys.path.insert(0, PARENTDIR)

from bmp213.motion import k_motionmanager
from common.devicedata import get_device
from common.akamaicrypto import AkamaiCrypto



@dataclass
class Eventparser:
    """
    package com.cyberfend.cyfsecurity.e
    """

    a: str = ""
    b: int = 0
    c: str = ""
    d: int = 0
    e: int = 0
    f: int = 0
    g: int = 0
    h: int = 0
    i: int = 0
    j: int = 0
    k: str = ""
    l: str = "-1"
    m: str = ""
    n: str = ""
    o: str = "default_performance"

    def reset(self):
        logger.debug("Resetting event result values")
        self.a = ""
        self.b = 0
        self.c = ""
        self.d = 0
        self.e = 0
        self.f = 0
        self.g = 0
        self.h = 0
        self.i = 0
        self.j = 0
        self.n = ""
        self.k = ""
        self.m = ""

@dataclass
class lContainer:
    """
    package com.cyberfend.cyfsecurity.l
    """

    a: float
    b: float
    c: float
    d: float
    e: float
    f: float
    g: float
    h: float
    i: float
    j: int
    k: int

@dataclass
class Constants:
    """
    package com.cyberfend.cyfsecurity;d
    """

    a: int = 0
    b: str = "https://apim.cformanalytics.com/"
    c: str = "sensor_data"
    d: bool = False
    e: int = 0
    f: int = -1
    g: int = 0
    h: int = 1800000
    i: str = ""
    j: str = ""
    k: int = 50000
    l: int = 0
    m: int = 0
    n: int = 0
    o: int = 0
    p: int = 0
    q: int = -1

    def _a(self, starttime):
        logger.debug("Resetting constants")
        self.a = time.time_ns() // 1000000
        self.e = (time.time_ns() // 1000000) - starttime
        self.g = 0
        self.n = 0

@dataclass
class j_MotionListener:
    e: int
    f: bool
    g: bool
    h: bool
    i: bool
    j: float
    k: float
    l: float
    m: float
    n: float
    o: float
    p: float
    q: float
    r: float
    s: float
    t: List
    u: int


@dataclass
class o_OrientationListener:
    """
    package com.cyberfend.cyfsecurity.o
    """
    f: bool
    g: bool
    h: bool
    i: bool
    j: bool
    k: int
    l: List
    m: List


@dataclass
class gcontainer:
    """
    package com.cyberfend.cyfsecurity.g
    """

    a: int
    b: str
    c: int
    d: bool


@dataclass
class ncontainer:
    """
    package com.cyberfend.cyfsecurity.n;
    """

    a: List
    b: List
    c: int
    d: int


class sensor_data(object):
    def __init__(self, orientation=True, motion=True, package="com.ae.ae"):
        """
        The idea is to keep state consistent across everal transformers on the same set of data

        """
        self.offset = random.randint(1, 500000)
        # offset from start time in ms
        self.starttime = (time.time_ns() // 1000000) - self.offset
        self.a = None
        self.b = k_motionmanager(
            b=False,
            c=0,
            d=0,
            e=0,
            f=[],
            g=[],
            h=[],
            i=0.0,
            j=0.0,
            k=0.0,
            l=0.0,
            m=0.0,
            n=0.0,
            o=0.0,
            p=0.0,
            q=0.0,
        )

